package com.luli.controllor;

import com.luli.entity.response.ResponseMsg;
import com.luli.service.impl.ProductService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.luli.Utils.ResponseMsgUtil.getSuccessMsg;

/**
 * 陆离
 * 2024/11/28
 */
@RequestMapping("/redis/test")
@RestController
public class RedisReDianData {

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private ProductService productService;

    /**
     * 删除redis
     * @param key
     * @return
     */
    @GetMapping("/w/remove/redis")
    public ResponseMsg<?> removeRedis(String key){
        redisTemplate.delete(key);
        return getSuccessMsg(null, "查询成功"  , null);

    }

    /**
     * 搜索
     * @param query
     * @return
     */
    @GetMapping("/r/search/product")
    public ResponseMsg<?> listProduct(String query) {
        return getSuccessMsg(null, "查询成功"  , productService.search(query));

    }

    /**
     * 热搜列表
     * @return
     */
    @ResponseBody
    @GetMapping("/r/list/hot/search")
    public ResponseMsg<?> listHotSearch() {
        return getSuccessMsg(null, "查询成功"  , productService.listHotSearch());

    }

    /**
     * 最近搜索列表
     * @return
     */
    @ResponseBody
    @GetMapping("/r/list/recent/search")
    public ResponseMsg<?> recentHotSearch() {
        return getSuccessMsg(null, "查询成功"  , productService.listRecentSearch());

    }

}

